package com.liuyi.netty.mqtt.processed.store;

import com.liuyi.netty.mqtt.common.MqttConst;

import java.util.Collection;

/**
 * Mqtt Sessiong Store
 * -
 */
public interface MqttSessionStore {

    /**
     * Get MqttSession
     */
    MqttSession getByClientId(String clientId);

    default MqttSession getDefaultByClientId(String clientId) {
        MqttSession session = getByClientId(clientId);
        if (session == null) {
            session = new MqttSession();
            session.setState(MqttConst.SessionState.NOT);
        }
        return session;
    }

    /**
     * set MqttSession
     */
    void createSession(String clientId);

    /**
     * clear MqttSession
     */
    void clearSession(String clientId);

    /**
     * refresh MqttSession
     * state is {@link MqttConst.SessionState#ONLINE}
     */
    void refreshSession(String clientId);

    /**
     * not MqttSession
     * state is {@link MqttConst.SessionState#NOT}
     */
    void notSession(String clientId);

    /**
     * offline MqttSession
     */
    void offlineSession(String clientId);

    /**
     * get connect count num
     */
    int count();

    /**
     * get all clientId Collection
     */
    Collection<String> allClientIds();
}
